// JavaScript Document
var myLeftTreeCookie = $.cookie('myLeftTreeCookie');
var myLeftTreeCookie = myLeftTreeCookie?myLeftTreeCookie.split(","):[];
var my = 
{
	showItem:function(o,oc)
	{
		var id = o.getAttribute('id');
		oc = oc || $(o).attr("class");
		if(oc == 'LiClose')
		{
			$(o).removeClass('LiClose').addClass('LiOpen').parents('ul').next('ul').slideUp("slow");
			var id = myLeftTreeCookie.indexOf(id);
			if(id != -1) myLeftTreeCookie.remove(id);
		}else
		{
			$(o).removeClass('LiOpen').addClass('LiClose').parents('ul').next('ul').slideDown("slow");
			id && myLeftTreeCookie.push(id);
		}
		$.cookie('myLeftTreeCookie',myLeftTreeCookie.join(","));
	}
};
var PctAction  = 
{
	form:null,
	note_error:'提示:\n\t请选择你要操作的商品!\t\n',
	check:function()
	{
		var a = this.form['gid[]'];
		if(a)
		{
			if(a['checked']) return true;
			for(var i=0;i<a.length;i++) if(a[i]['checked']) return true;
		}
		return false;
	},
	all:function()
	{
		checkbox.check(this.form['gid[]']);
	},
	reverse:function()
	{
		checkbox.reverse(this.form['gid[]']);
	},
	del:function()
	{
	    var note = "提示:\n\t删除将无法恢复!您确定要删除所选的商品吗？\t\n";
	    var chk  = this.check();
		if(chk && confirm(note))
		{
			this.form.Pact.value = "Pctdel";
			this.form.submit();
		}else if(!chk)
		{
			alert(this.note_error);	
		}
	},
	up:function()
	{
		var note = "提示:\n\t您确定要上架所选的商品吗!\t\n";
		var chk  = this.check();
		if(chk && confirm(note))
		{
			this.form.Pact.value = "PctUploadDate";
			this.form.submit();
		}else if(!chk)
		{
			alert(this.note_error);	
		}
	},
	down:function()
	{
		var note = "提示:\n\t您确定要下架所选的商品吗!\t\n";
		var chk  = this.check();
		if(chk && confirm(note))
		{
			this.form.Pact.value = "PctDown";
			this.form.submit();
		}else if(!chk)
		{
			alert(this.note_error);	
		}
	},
	good:function()
	{
		var c=0,a = this.form['gid[]'];
		var chk = this.check();
		if(chk)
		{ 
			for(var i=0;i<a.length;i++)
			{
				if(a[i]['checked']) c++;
				if(c>6)
				{
					 alert("提示:\n\t店铺推荐商品数不能大于6个!\t\n");
					 return true;
				}
			}
		}
		/////////////////////////
		var note = "提示:\n\t您确定要设定所选为店铺推荐商品吗!\t\n";
		var chk  = this.check();
		if(chk && confirm(note))
		{
			this.form.Pact.value = "PctGood";
			this.form.submit();
		}else if(!chk)
		{
			alert(this.note_error);	
		}
	},	
	good_del:function()
	{
		var note = "提示:\n\t您确定要取肖所选商品的推荐吗!\t\n";
		var chk  = this.check();
		if(chk && confirm(note))
		{
			this.form.Pact.value = "PctGood_del";
			this.form.submit();
		}else if(!chk)
		{
			alert(this.note_error);	
		}
	},
	set:function(o)
	{
		this.form = o;
	}
}
$(function()
{
	$("li:last","ul.UlList").addClass("LiEnd");	
	$("ul:last li:last","div.side_main").addClass("LiFoot");
	var i,len = myLeftTreeCookie.length;
	for(i=0;i<len;i++)
	{
		$("#"+myLeftTreeCookie[i]).removeClass('LiOpen').addClass('LiClose').parents('ul').next('ul').show();
	}
});